set.seed(1782318297)

library(stargazer)
library(tidyverse)
library(pacman)

#Sensitivity Analysis

outcome_equation <- lm(sup ~ vic + sat + aoj11 + age + female + education + income + country + race + urban, weights = weights, 
                       data = full_data)

mediator_equation <- lm(sat ~ vic + aoj11 + age + female + education + income + country + race + urban, weights = weights,
                        data = full_data)

pacman::p_load(sensemakr)

sensitivity_m <- sensemakr::sensemakr(model = mediator_equation, treatment = "vic", 
                                      benchmark_covariates = "income", 
                                      kd = 1:3, ky = 1:3, q = 1, 
                                      reduce = T)

plot(sensitivity_m, ylab = "Partial R2 of confounder(s) with the mediator")

summary(sensitivity_m)

sensitivity_y <- sensemakr::sensemakr(model = outcome_equation, treatment = "sat", 
                                      benchmark_covariates = "income", 
                                      kd = 1:3, ky = 1:3, q = 1, 
                                      reduce = T)

plot(sensitivity_y, xlab = "Partial R2 of confounder(s) with the mediator")

summary(sensitivity_y)
